﻿using System;
using System.Configuration;

using BizElements.BusinessLayer;

namespace BizElements.Web
{
    /// <summary>Creates <see cref="ISearchFilterTextSource"/> object configured in application's configuration file.</summary>
    internal static class SearchFilterTextSourceFactory
    {
        #region Configuration.

        static readonly string TextSourceAssembly = ConfigurationManager.AppSettings["BizElements.Web.SearchFilter.TextSourceAssembly"];
        static readonly string TextSourceClass = ConfigurationManager.AppSettings["BizElements.Web.SearchFilter.TextSourceClass"];

        #endregion

        #region GetTextSource.

        /// <summary>Creates <see cref="ISearchFilterTextSource"/> object configured in application's configuration file.</summary>
        public static ISearchFilterTextSource GetTextSource()
        {
            ISearchFilterTextSource textSource = null;
            if (!string.IsNullOrEmpty(TextSourceAssembly) && !string.IsNullOrEmpty(TextSourceClass))
                textSource = ReflectionUtil.TryCreateInstance(TextSourceAssembly, TextSourceClass) as ISearchFilterTextSource;

            if (textSource == null)
                textSource = new SearchFilterTextSource();

            // Previously NullSearchFilterTextSource wass used as default.
            // if (textSource == null) textSource = NullSearchFilterTextSource.GetInstance();

            return textSource;
        }

        #endregion
    }
}